var base = getApp();
Page({
  data: {
    typeArr: [
      {
        id: 1,
        name: '仅退款'
      },
      {
        id: 2,
        name: '退货退款'
      },
      {
        id: 3,
        name: '换货'
      }
    ],
    typeIndex: 0,
    statusArr: [
      {
        id: 1,
        name: '未收到货'
      },
      {
        id: 2,
        name: '已收到货'
      }
    ],
    statusIndex: 0,
    causesArr: [
      {
        id: 1,
        name: '商品成分描述不符'
      },
      {
        id: 2,
        name: '质量问题'
      },
      {
        id: 3,
        name: '生产日期，保质期描述不符'
      },
      {
        id: 4,
        name: '三无产品'
      },
      {
        id: 5,
        name: '图片/产地/批号/规格等描述不符'
      },
      {
        id: 6,
        name: '卖家发错货'
      },
      {
        id: 7,
        name: '假冒品牌'
      },
      {
        id: 8,
        name: '收到商品少件或破损'
      },
      {
        id: 9,
        name: '其他'
      }
    ],
    causesIndex: 0,
    gid:0,
    oid:0,
    coid:0,
    skuid:0,
    money:"",
    content:"",
    url: base.path.url
  },

  bindChange1: function (e) {
    this.setData({
      typeIndex: e.detail.value
    })
  },
  bindChange2: function (e) {
    this.setData({
      statusIndex: e.detail.value
    })
  },
  bindChange3: function (e) {
    this.setData({
      causesIndex: e.detail.value
    })
  },
  bindMoney: function (e) {
    this.data.money = e.detail.value
  },
  bindContent: function (e) {
    this.data.content = e.detail.value
    console.log(this.data.content)
  },
  onLoad: function (e) {
    var that = this;
    var gid = parseInt(e.gid);
    var oid = parseInt(e.oid);
    var coid = parseInt(e.coid);
    var skuid = parseInt(e.skuid);
    that.data.gid = gid;
    that.data.oid = oid;
    that.data.coid = coid;
    that.data.skuid = skuid;
    
  },
  bindSubmit: function () {
    var that = this;
    var typeIndex = that.data.typeIndex;
    var statusIndex = that.data.statusIndex;
    var causesIndex = that.data.causesIndex;
    var type = that.data.typeArr[typeIndex].id;
    var wuliu_status = that.data.statusArr[statusIndex].id;
    var rason_type = that.data.causesArr[causesIndex].id;
    // console.log(type)
    // return;
    if (typeIndex!=0){
      wuliu_status="";
    }
    if(that.data.money==""){
      wx.showModal({
        showCancel: false,
        content: '退款金额为必填项',
        success: function (res) {
          if (res.confirm) {
            
          }
        }
      })
      return;
    }
    wx.request({
      url: base.path.api + 'Goods.CustomerService',
      data: {
        md5key: base.user.session_key,
        aid: base.user.aid,
        oid: that.data.oid,
        gid: that.data.gid,
        coid: that.data.coid,
        skuid: that.data.skuid,
        type: type,
        wuliu_status: wuliu_status,
        rason_type: rason_type,
        money: that.data.money,
        content: that.data.content
      },
      method: "POST",
      header: base.user.header,
      success: function (response) {
        var result = response.data;
        console.log(result)
        if (result.ret == 200) {
          wx.showModal({
            showCancel: false,
            content: '提交成功！',
            success: function (res) {
              if (res.confirm) {
                wx.switchTab({
                  url: '/pages/user/user',
                })
              }
            }
          })
        }
      }
    })
  },
  onShareAppMessage: function () {
    return {
      title: base.user.shareTitle,
      desc: base.user.shareDesc,
      path: '/pages/index/index',
      success: function (res) {
        // 转发成功
      },
      fail: function (res) {
        // 转发失败
      }
    }
  },

})